package com.grudesign.stutrip.controller;


import com.grudesign.stutrip.common.ReturnInfo;
import com.grudesign.stutrip.entity.Po.NewinfoPo;
import com.grudesign.stutrip.entity.Vo.newsQueryVo;
import com.grudesign.stutrip.service.NewInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 咨询表 前端控制器
 * </p>
 *
 * @author wx
 * @since 2022-05-09
 */
@RestController
@RequestMapping("/newinfo")
public class NewinfoController {

    @Autowired
    private NewInfoService newInfoService;
    @GetMapping("getAllNews")
    public Object getNewsList(){
        Object obj =   newInfoService.getNewsList();
        return obj;
    }

    @GetMapping("/getSrc")
    public Object getSource(){
        Object obj = newInfoService.getSource();
        return obj;
    }


    @PostMapping("/queryNews/{cur}/{li}")
    public Object getQueryNews(@PathVariable String cur,
                               @PathVariable String li,
                               @RequestBody(required = false) newsQueryVo queryVo){
        Object obj =  newInfoService.queryNews(cur,li,queryVo);
        return obj;
    }

    @PostMapping("/addNews")
    public Object addNews(@RequestBody NewinfoPo newinfoPo){
        boolean isSave = newInfoService.save(newinfoPo);
        return isSave?new ReturnInfo("200","ok"):new ReturnInfo("-1","err");
    }
    @PutMapping("/editNews")
    public Object editNews(@RequestBody NewinfoPo newinfoPo){
        boolean edit = newInfoService.updateById(newinfoPo);
        return edit?new ReturnInfo("200","ok"):new ReturnInfo("-1","err");
    }
    @DeleteMapping("/{id}")
    public  Object delNews(@PathVariable String id){
        boolean isDel = newInfoService.removeById(id);
        return isDel?new ReturnInfo("200","ok"):new ReturnInfo("-1","err");
    }
}

